package com.rw.coco.reply.impl;

import com.rw.coco.api.reply.mapper.AdvancedReply;
import com.rw.coco.handler.message.event.CocoGroupMessageEvent;
import com.rw.coco.handler.message.event.CocoMessageEvent;
import com.rw.coco.handler.message.event.CocoPrivateMessageEvent;
import com.rw.coco.reply.constants.AdvanceReplyKey;
import com.rw.coco.reply.reader.CocoPropertiesReader;

import java.text.MessageFormat;

/**
 * 通常回复
 */
public class PropertiesAdvancedReply implements AdvancedReply {
    private final CocoPropertiesReader reader;

    public PropertiesAdvancedReply(CocoPropertiesReader reader) {
        this.reader = reader;
    }

    @Override
    public String dismissGroup(CocoGroupMessageEvent event) {
        return reader.get(AdvanceReplyKey.DISMISS_GROUP);
    }

    @Override
    public String dismissPrivate(CocoPrivateMessageEvent event) {
        return reader.get(AdvanceReplyKey.DISMISS_PRIVATE);
    }

    @Override
    public String groupFreqExceededWarn(CocoGroupMessageEvent event, int warnExceeded, int maxWarnCount) {
        String reply = reader.get(AdvanceReplyKey.GROUP_FREQ_EXCEEDED_WARN);
        return MessageFormat.format(reply, warnExceeded, maxWarnCount);
    }

    @Override
    public String groupFreqExceeded(CocoGroupMessageEvent event, int maxWarnCount) {
        return reader.get(AdvanceReplyKey.GROUP_FREQ_EXCEEDED);
    }

    @Override
    public String privateFreqExceededWarn(CocoPrivateMessageEvent event, int warnExceeded, int maxWarnCount) {
        String reply = reader.get(AdvanceReplyKey.PRIVATE_FREQ_EXCEEDED_WARN);
        String nick = event.getNick();
        return MessageFormat.format(reply, nick, warnExceeded, maxWarnCount);
    }

    @Override
    public String privateFreqExceeded(CocoPrivateMessageEvent event, int maxWarnCount) {
        return reader.get(AdvanceReplyKey.PRIVATE_FREQ_EXCEEDED);
    }

    @Override
    public String botOn(CocoGroupMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_ON);
    }

    @Override
    public String botOff(CocoGroupMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_OFF);
    }

    @Override
    public String botAlreadyOn(CocoGroupMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_ALREADY_ON);
    }

    @Override
    public String botOnWithoutAuthorize(CocoGroupMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_ON_WITHOUT_AUTHORIZE);
    }

    @Override
    public String botOffWithoutAuthorize(CocoGroupMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_OFF_WITHOUT_AUTHORIZE);
    }

    @Override
    public String botSwitchOn(CocoMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_SWITCH_ON);
    }

    @Override
    public String botSwitchAlreadyOn(CocoMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_SWITCH_ALREADY_ON);
    }

    @Override
    public String botSwitchOff(CocoMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_SWITCH_OFF);
    }

    @Override
    public String botSwitchAlreadyOff(CocoMessageEvent event) {
        return reader.get(AdvanceReplyKey.BOT_SWITCH_ALREADY_OFF);
    }

    @Override
    public String blackUser(CocoMessageEvent event, String userId) {
        String reply = reader.get(AdvanceReplyKey.BLACK_USER);
        return MessageFormat.format(reply, userId);
    }

    @Override
    public String whiteUser(CocoMessageEvent event, String userId) {
        String reply = reader.get(AdvanceReplyKey.WHITE_USER);
        return MessageFormat.format(reply, userId);
    }

    @Override
    public String blackGroup(CocoMessageEvent event, String id) {
        String reply = reader.get(AdvanceReplyKey.BLACK_GROUP_USER);
        return MessageFormat.format(reply, id);
    }

    @Override
    public String whiteGroup(CocoMessageEvent event, String id) {
        String reply = reader.get(AdvanceReplyKey.WHITE_GROUP_USER);
        return MessageFormat.format(reply, id);
    }
}
